package prom

import (
	"bytes"
	"fmt"
	"github.com/prometheus/common/version"
	"net/http"
)

type Client struct {
	head *http.Header
	url  string
}

func OpenProm(url string) (*Client, error) {
	head := &http.Header{}
	head.Add("Content-Encoding", "snappy")
	head.Set("Content-Type", "application/x-protobuf")
	head.Set("User-Agent", fmt.Sprintf("Prometheus/%s", version.Version))
	head.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
	return &Client{
		url:  url,
		head: head,
	}, nil
}

func (r *Client) WriteData(data []byte) error {
	httpReq, err := http.NewRequest("POST", r.url, bytes.NewReader(data))
	if err != nil {
		return err
	}
	httpReq.Header = *r.head

	if _, err = http.DefaultClient.Do(httpReq); err != nil {
		return err
	}

	return nil
}

func (r *Client) Query(query, time string) error {
	http.Get(fmt.Sprintf("dddd %v  fdsfds%v"))
	return nil
}
